Propagate configuration parser errors
authorAlex Crichton <alex@alexcrichton.com>
Fri, 24 Oct 2014 15:48:00 +0000 (08:48 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 27 Oct 2014 19:59:34 +0000 (12:59 -0700)
Closes #743

src/cargo/util/config.rs
tests/test_cargo_compile.rs

index 0cf39c770dcb23b512c3c8a056cb059ba1c83878..e0a57e0401bcce9f67f12393cdf34037feef9833 100644 (file)
@@ -255,7 +255,7 @@ pub fn all_configs(pwd: Path) -> CargoResult<HashMap<string::String, ConfigValue
         let value = try!(ConfigValue::from_toml(&path, toml::Table(table)));
         try!(cfg.merge(value));
         Ok(())
-    }).map_err(|_| human("Couldn't load Cargo configuration")));
+    }).chain_error(|| human("Couldn't load Cargo configuration")));
 
 
     match cfg {
@@ -288,20 +288,14 @@ fn find_in_tree<T>(pwd: &Path,
 fn walk_tree(pwd: &Path,
              walk: |File| -> CargoResult<()>) -> CargoResult<()> {
     let mut current = pwd.clone();
-    let mut err = false;
 
     loop {
         let possible = current.join(".cargo").join("config");
         if possible.exists() {
             let file = try!(File::open(&possible));
 
-            match walk(file) {
-                Err(_) => err = false,
-                _ => ()
-            }
+            try!(walk(file));
         }
-
-        if err { return Err(internal("")); }
         if !current.pop() { break; }
     }
 
index afb48727d07bfba4a1ae066e1867370e6483dcc6..6de108de407146faa2481d1476c281abbc556fd6 100644 (file)
@@ -1684,3 +1684,29 @@ test!(ignore_bad_directories {
     assert_that(foo.process(cargo_dir().join("cargo")).arg("build"),
                 execs().with_status(0));
 })
+
+test!(bad_cargo_config {
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file(".cargo/config", r#"
+              this is not valid toml
+        "#);
+    assert_that(foo.cargo_process("build").arg("-v"),
+                execs().with_status(101).with_stderr("\
+Couldn't load Cargo configuration
+
+Caused by:
+  could not parse Toml manifest; path=[..]
+
+Caused by:
+  could not parse input TOML
+[..].cargo[..]config:2:20-2:21 expected `=`, but found `i`
+
+"));
+})